<?php
namespace Weiserver\Controller;
use Common\Controller\WeibaseController;
class WeinetController extends WeibaseController {
	
	/**
	*	初始化方法
	*/
	protected function _initialize(){
		//parent::_initialize();
	}
	
	/**
	*	微信服务器交互服务
	*/
	public function index(){
		$tokenkey=I('get.tokenkey');
		$weinet=M('Weinet');
		$where=array('tokenkey'=>$tokenkey);
		
		$rs=$weinet->where($where)->select();
		$scriptarticle=array();
		foreach($rs as $vo){
			$id=$vo['id'];
			$secondjson=$vo['secondjson'];
			$secondjson=htmlspecialchars_decode($secondjson);
			$secondjson=preg_replace("/\s/"," ",$secondjson);
			$secondjson=preg_replace("/<script[\s\S]*?<\/script>/i","",$secondjson);
			
			$secondarr=json_decode($secondjson,1);
			if('article'==$secondarr['type']){
				$secondarr['id']=$id;
				$scriptarticle[]=$secondarr;
			}
		}
		
		$this->assign('scriptarticle',$scriptarticle);
		$this->assign('list',$rs);
		$this->display();
	}
}